package com.xctech.ipb.dpn.hyc.controller;

import com.xctech.ipb.dpn.common.utils.JsonUtils;
import com.xctech.ipb.dpn.common.vo.Result;
import com.xctech.ipb.dpn.hyc.constant.TopicConstants;
import com.xctech.ipb.dpn.hyc.domain.service.OrderService;
import com.xctech.ipb.dpn.hyc.domain.service.OrderPowerService;
import com.xctech.ipb.dpn.hyc.model.req.OrderReq;
import com.xctech.ipb.dpn.hyc.model.req.SyncOrderDelReq;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

import static com.xctech.ipb.dpn.common.response.ResponseCode.SUCCESS;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderPowerService orderPowerService;

    //增量同步订单
    @PostMapping("/sync")
    public Result<String> sync(@Valid @RequestBody OrderReq req) {

        log.info("订单实时同步-数量:{}", req.getListSize());
        String topicBody = JsonUtils.toJsonString(req);
        kafkaTemplate.send(TopicConstants.TOPIC_ORDER_SYNC, topicBody);
        
        return Result.successOne(SUCCESS.name());
    }

    //全量同步订单
    @PostMapping("/syncAll")
    public Result<String> syncAll(@Valid @RequestBody OrderReq req) {
        log.info("订单全量-数量:{}", req.getListSize());
        return Result.successOne(SUCCESS.name());
    }

    @PostMapping("/syncDel")
    public Result<String> syncDelete(@Valid @RequestBody SyncOrderDelReq req) {

        log.info("订单删除同步-数量:{}", req.getListSize());
        String topicBody = JsonUtils.toJsonString(req);
        kafkaTemplate.send(TopicConstants.TOPIC_ORDER_SYNC_DEL, topicBody);

        return Result.successOne(SUCCESS.name());
    }

}
